<?php

$output5 = $output6=$res5=$res6=[];
// ffprobe https://material-center.meitudata.com/material/video/62baba697310d4908.mp4
// http://ffmpeg-online-func.ffmpeg-online.1935738789844103.cn-hangzhou.fc.devsapp.net/?cmd=ffprobe%20https%3A%2F%2Fmaterial-center.meitudata.com%2Fmaterial%2Fvideo%2F62baba697310d4908.mp4
// ffmpeg -i https://material-center.meitudata.com/material/video/62baba697310d4908.mp4 -ss 0 -to 3 -c:v libx264 -c:a aac -strict experimental -r 3 -b:v 100k  h264-3s-r3.mp4 -y
// http://ffmpeg-online-func.ffmpeg-online.1935738789844103.cn-hangzhou.fc.devsapp.net/?cmd=ffmpeg%20%20-i%20https%3A%2F%2Fmaterial-center.meitudata.com%2Fmaterial%2Fvideo%2F62baba697310d4908.mp4%20-ss%200%20-to%203%20-c%3Av%20libx264%20-c%3Aa%20aac%20-strict%20experimental%20-r%203%20-b%3Av%20100k%20%20h264-3s-r3.mp4%20-y%20%202%3E%261
if($_GET['cmd']){
    $json = [];
    if(substr($_GET['cmd'],0,7)!="ffmpeg " && substr($_GET['cmd'],0,8)!="ffprobe " ){
        exit("只支持ffmpeg和ffprobe命令");
    }
    $orgCMD = $_GET['cmd'];

    //输出到指定目录
    $cmd = preg_replace('/\s(\w+\.\w+)$/','./output/$1',$orgCMD);


    $cmd = $cmd.' 2>&1';
    exec($cmd ,$output5,$res5);
    exec('ls -al ./',$output6,$res6);


    $json['cmd'] = $cmd;
    $json['res'] = implode("\n",$output5);

    $text = '<pre>';
    $text .= '执行：'.$_GET['cmd']."\n";

    $text .= "\n\n============运行结果============\n";
    $text .= implode("\n",$output5);
    $text .= "\n\n============当前目录============\n";
    $text .= implode("\n",$output6);
    $text .= '</pre>';

    if ($_GET['format']=='json'){
        echo json_encode($json,JSON_UNESCAPED_UNICODE);
    }else{
        echo $text;
    }

}else{
    exit("示例： http://ffmpeg.huanglixiang.com/?page=cmd&cmd=ffprobe%20https%3A%2F%2Fmaterial-center.meitudata.com%2Fmaterial%2Fvideo%2F62baba697310d4908.mp4");

}

